<?php
$mysqlFile = "";
	$mysqlFile .= "CREATE TABLE `$table` (".$CR;
	$pkAr = array();
	for ($i=0;$i<count($var);$i++){	
		$fname = $var[$i]["name"];
		$ftype = $var[$i]["type"];
		$fleng = $var[$i]["length"];
		$fdefa = $var[$i]["default"];
		$fextr = $var[$i]["extra"];
		$fprim = $var[$i]["PK"];
		
		switch (strtoupper($ftype)){
			case "VARCHAR":
				$tipo = strtoupper($ftype)."( ".$fleng." )";
				break;
			case "TINYINT":
				$tipo = strtoupper($ftype);
				if ($fleng!="")
					$tipo .="(".$fleng.")";
				break;
			case "INT":
				$fleng= $fleng==""?"11":$fleng;
				$tipo = strtoupper($ftype)."(".$fleng.")";
				break;
			case "MEDIUMINT":
				$tipo = strtoupper($ftype);
				if ($fleng!="")
					$tipo .="(".$fleng.")";
				break;
			case "BIGINT":
				$tipo = strtoupper($ftype);
				if ($fleng!="")
					$tipo .="(".$fleng.")";
				break;
			case "FLOAT":
				$tipo = strtoupper($ftype);
				if ($fleng!="")
					$tipo .="(".$fleng.")";
				break;
			case "DOUBLE":
				$tipo = strtoupper($ftype);
				if ($fleng!="")
					$tipo .="(".$fleng.")";
				break;
			case "CHAR":
				$tipo = strtoupper($ftype);
				if ($fleng!="")
					$tipo .="(".$fleng.")";
				break;
			case "DATE":
				$tipo = strtoupper($ftype);
				break;
			case "DATETIME":
				$tipo = strtoupper($ftype);
				break;
			case "BLOB":
				$tipo = strtoupper($ftype);
				break;
			case "TEXT":
				$tipo = strtoupper($ftype);
				break;
			case "ENUM":
				$tipo = strtoupper($ftype)."($fdefa)" ;
				$fdefa='';
				break;
			case "ONOFF":
				$tipo = "TINYINT (1)" ;
				$fdefa='0';
				break;
			case "TIMESTAMP":
				$tipo = strtoupper($ftype);
				$fdefa='';
				break;
		}
		//ALTER TABLE `te` ADD `sadasd` ENUM( 'a', 'as', 'sd' ) NOT NULL ;
		$mysqlFile .="\t `".$var[$i]["name"]."` ";
		
		$mysqlFile .=" ".$tipo." NOT NULL ";
		
		if ($fdefa=="" || $fdefa=="''" || $fdefa=="\"\""){
			$fdefa="";
		}
		if ($fdefa!="")
			$mysqlFile .=" DEFAULT '".$fdefa."' ";
		
		$fextr=strtoupper($fextr);
		if ($fextr=="AUTONUMBER" || $fextr=="AN"|| $fextr=="AUTO_INCREMENT"|| $fextr=="AI"){
			$fextr = "AUTO_INCREMENT";
		}else{
			$fextr = "";
		}
		
		$mysqlFile .=" ".$fextr." ";
		
		$fprim =strtoupper($fprim );
		if ($fprim =="PRIMARY_KEY" || $fprim == "PK" || $fprim == "PRIMARYKEY"){
			array_push($pkAr,"PRIMARY KEY (`".$fname."`)");
		}
		
		$mysqlFile .=", ".$CR;
	}
	if (count($pkAr)==0){
		// no primary keys defined
		$mysqlFile = rtrim($mysqlFile,", ".$CR);
	}else{
		for ($i=0;$i<count($pkAr);$i++){
			$mysqlFile .=" ".$pkAr[$i].", ".$CR;
		}
		$mysqlFile = rtrim($mysqlFile,", ".$CR);
	}
	
	$mysqlFile .=$CR.");";
?>